package com.xy.controller.admin.system;

import com.xy.api.model.dto.system.UserInfoDTO;
import com.xy.api.model.request.system.KeywordPageRequest;
import com.xy.api.model.request.system.LoginRequest;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.system.IUserService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system/user")
public class UserInfoController extends BaseController {

    @Autowired
    private IUserService userService;

    @PostMapping("/login")
    public R login(@RequestBody LoginRequest request) {
        UserInfoDTO userInfo = userService.login(request);
        return success(userInfo);
    }

    @PostMapping("/getUserInfo")
    public R getUserInfo() {
        UserInfoDTO userInfo = userService.getUserInfo();
        return success(userInfo);
    }

    @PostMapping("/list")
    public R queryUserList(@RequestBody KeywordPageRequest request) {
        Rows<UserInfoDTO> rows = userService.queryUserList(request);
        return success(rows);
    }

    @PostMapping("/detail")
    public R queryUserDetail(@RequestBody UserInfoDTO request) {
        UserInfoDTO userDetail = userService.queryUserDetail(request.getId());
        return success(userDetail);
    }

    @PostMapping("/edit")
    public R editUser(@RequestBody UserInfoDTO request) {
        userService.editUser(request);
        return success();
    }

    @PostMapping("/delete")
    public R deleteUser(@RequestBody UserInfoDTO request) {
        userService.deleteUser(request.getId());
        return success();
    }


}
